/**
 * 
 */
package cn.softTank.BpelModelImpl;

import org.dom4j.Element;

import cn.softTank.BpelModel.FromParts;
import cn.softTank.BpelModel.MessageExchange;
import cn.softTank.BpelModel.Receive;
import cn.softTank.BpelModel.Variable;

/**
 * @author Yuzone (smartzxy@gmail.com)
 * 
 */
public class ReceiveImpl extends PartnerActivityImpl implements Receive {

	private boolean createInstance;
	private boolean setCreateInstance;
	private FromParts fromParts;
	private MessageExchange messageExchange;
	private Variable variable;

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Receive#getCreateInstance()
	 */
	@Override
	public Boolean getCreateInstance() {
		return createInstance;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Receive#getFromParts()
	 */
	@Override
	public FromParts getFromParts() {
		return fromParts;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Receive#getMessageExchange()
	 */
	@Override
	public MessageExchange getMessageExchange() {
		return messageExchange;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Receive#getVariable()
	 */
	@Override
	public Variable getVariable() {
		return variable;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Receive#isSetCreateInstance()
	 */
	@Override
	public boolean isSetCreateInstance() {
		return setCreateInstance;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Receive#setCreateInstance(java.lang.Boolean)
	 */
	@Override
	public void setCreateInstance(Boolean value) {
		createInstance = value;
		setCreateInstance = true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.softTank.BpelModel.Receive#setFromParts(cn.softTank.BpelModel.FromParts
	 * )
	 */
	@Override
	public void setFromParts(FromParts value) {
		fromParts = value;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.softTank.BpelModel.Receive#setMessageExchange(cn.softTank.BpelModel
	 * .MessageExchange)
	 */
	@Override
	public void setMessageExchange(MessageExchange value) {
		messageExchange = value;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.softTank.BpelModel.Receive#setVariable(cn.softTank.BpelModel.Variable)
	 */
	@Override
	public void setVariable(Variable value) {
		variable = value;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Receive#unsetCreateInstance()
	 */
	@Override
	public void unsetCreateInstance() {
		setCreateInstance = false;
	}

	@Override
	public Element toElement() {
		node = super.toElement();
		node.setName("receive");
		if (variable != null)
			node.addAttribute("variable", variable.getName());
		if (setCreateInstance)
			if (createInstance)
				node.addAttribute("createInstance", "yes");
			else
				node.addAttribute("createInstance", "no");
		if (messageExchange != null)
			node.addAttribute("messageExchange", messageExchange.getName());
		if (fromParts != null)
			node.add(fromParts.toElement());
		return node;
	}

}
